import { CHANGE_INPUT, ADD_ITEM, DELETE_ITEM, GET_LIST, GET_MY_LIST } from '../store/actionTypes'
import axios from 'axios';

// input输入
export const changeInputAction = (value) => ({
    type: CHANGE_INPUT,
    value
});

// 按钮添加
export const addItemAction = () => ({
    type: ADD_ITEM,
});

// 删除添加
export const deleteItemAction = (index) => ({
    type: DELETE_ITEM,
    index
});

// 请求外部列表接口
export const getListAction = (data) => ({
    type: GET_LIST,
    data
});

export const getTodoList = () => {
    return (dispatch) => {
        axios.get('https://www.fastmock.site/mock/6ff52d018330d0650bed38718fde63b1/redux/getList').then(res => {
            const data = res.data;
            const action = getListAction(data);
            dispatch(action);
        });
    }
}

export const getMyListAction = () => ({
    type: GET_MY_LIST
});